package com.liuya.db.orm;

import com.liuya.db.MapStorageObjectNewer;
import com.liuya.db.MapStorgeObject;
import com.liuya.db.ObjectNewer;
import com.liuya.db.orm.SingleValueTableAdapter;

public class DefaultSingleValueTableAdapter implements SingleValueTableAdapter {
	private String mapKey;

	// private String idColumnName;

	public DefaultSingleValueTableAdapter(String mapKey/* , String idColumnName */) {
		super();
		this.mapKey = mapKey;
		// this.idColumnName=idColumnName;
	}

	public void combine(Object o, Object extractValue) {
		MapStorgeObject mso = (MapStorgeObject) o;
		mso.put(mapKey, extractValue);
	}

	public Object extract(Object o) {
		MapStorgeObject mso = (MapStorgeObject) o;
		return mso.get(mapKey);
	}

	public Object extractEvenNoValueExist(Object o) {
		Object extract = extract(o);
		if (extract == null) {
			// MapStorgeObject another=new MapStorgeObject();
			// Object idValue=mso.get( mainTableIdColumnName );
			// another.put( mainTableIdColumnName, idValue );
			// return another;
			return o;
		} else {
			return extract;
		}
	}

	public ObjectNewer getObjectNewer() {
		return new MapStorageObjectNewer();
	}
}
